<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script>

// var twoSum = function(numbers, target) {
//     let num
//     for (let i = 0; i < numbers.length; i++) {
//         num = target - numbers[i]
//         console.log('numbers.slice(i+1).indexOf(num):', numbers.slice(i+1).indexOf(num))
//         if (numbers.slice(i+1).indexOf(num) !== -1){
//             return [i, numbers.slice(i+1).indexOf(num)+i+1]
//         }
//     }
// }
var twoSum = function(numbers, target) {
    var num, obj = {}
    for(var i = 0; i < numbers.length; i++) {
        console.log('numbers[i]:', numbers[i])
        if (obj[numbers[i]] === undefined) {
            num  = target - numbers[i]
            obj[num] = i
        } else {
            console.log('111111111')
            console.log('bj[num]:', obj[numbers[i]])
            console.log('i:', i)
            return [obj[numbers[i]], i]
        }
        console.log('obj:', obj)
    }
};

// var numbers = [2,7,11,15], target = 9
// var numbers = [5, 25, 75], target = 100
var numbers = [2, 3, 4], target = 6
console.log('numbers:', numbers)
console.log('target:', target)
console.log(twoSum(numbers, target))

</script>
</body>
</html>